﻿using System;
using System.Collections.Generic;
using System.Text;
using Mang24k99.Model.COMM;
using NHibernate;
using NHibernate.Expression;
using Castle.ActiveRecord.Queries;
namespace Mang24k99.Business.COMM
{
    public partial class BKtCommTreeconfig
    {
        public static IList<MKtCommTreeconfig> FindAll()
        {
            ICriterion[] criteria = new ICriterion[]
            {
            };
            return MKtCommTreeconfig.SelectAll(criteria);
        }

        public static MKtCommTreeconfig Find(object ID)
        {
            return MKtCommTreeconfig.SelectByPrimaryKey(ID);
        }
        public static MKtCommTreeconfig FindOne()
        {
            ICriterion[] criteria = new ICriterion[]
            {
            };
            return MKtCommTreeconfig.SelectOne(criteria);
        }
        public static MKtCommTreeconfig FindFirst()
        {
            ICriterion[] criteria = new ICriterion[]
            {
            };
            return MKtCommTreeconfig.SelectFirst(criteria);
        }

        public static IList<MKtCommTreeconfig> FindALLByProperty(string property, object value)
        {
            return MKtCommTreeconfig.SelectALLByProperty(property, value);
        }

        public static IList<MKtCommTreeconfig> FindALLSliced(int firstResult, int maxResult)
        {
            ICriterion[] criteria = new ICriterion[]
            {
            };
            return MKtCommTreeconfig.SelectALLSliced(firstResult, maxResult, criteria);
        }
        public static IList<MKtCommTreeconfig> FindALLQuery(int firstResult, int maxResult)
        {
            string strHql = @"Select MKtCommTreeconfig"
                          + " from"
                          + " MKtCommTreeconfig MKtCommTreeconfig"
                          //+ " where"
                          //+ " MKtCommTreeconfig.IsValidate = 1"
                          ;
            SimpleQuery query = new SimpleQuery(typeof(MKtCommTreeconfig), strHql);
            query.SetQueryRange(firstResult, maxResult);
            return MKtCommTreeconfig.SelectAllQuery(query);
        }
        public static int Count()
        {
            ICriterion[] criteria = new ICriterion[]
            {
                Expression.Eq("IsValidate",1),
            };
            return MKtCommTreeconfig.Counts(criteria);
        }
        public static bool Exists(object id)
        {
            return MKtCommTreeconfig.Exist(id);
        }
        /// <summary>
        /// 验证树名是否存在
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static bool NameValidate(string name)
        {
            string where = " where config.TreeName='"+name+"'";
            MKtCommTreeconfig[] configlist = (MKtCommTreeconfig[])MKtCommTreeconfig.SelectByWhere(where);
            if (configlist.Length>0)
            {
                return false;
            }
            return true;
        }
    }
}
